<?php
// +----------------------------------------------------------------------
// | Author: ZYN Fl
// +----------------------------------------------------------------------
namespace app\admin\controller;
use think\Controller;
use think\Request;
use think\Db;
use think\captcha\Captcha;

class Login extends Controller
{
	/*
	* 验证码
	*/
	public function verify(){
        $verify = new Captcha (config('verify'));
        return $verify->entry();
    }
	/*
	*显示登录页
	*/ 
    public function index()
    {
        return $this->fetch();
    }
	public function login(){
		if (!request()->isAjax()){
			$this->error('提交方式不正确',url('index'));
		}
		$username=input('user');
		$password=input('pawd');
		$verify =new Captcha ();
        if ($verify->check(input('verify'))) {
            $admin=Db::name('admin')->where(array('adminuser'=>$username))->find();
			if($admin){
				if(Db::name('admin')->where(array('adminuser'=>$username,'adminpawd'=>MD5($password)))->find()){
					session('username',$admin['adminuser']);
					session('aid',$admin['id']);
					return 1;
				}else{
					return 2;  //密码错误
				}
			}else{
				return 3;   //账号错误
			}
        }else{
        	return 4;  //验证码错误
        }
	}
	public function loginout(){
		session('aid',null);
		//$this->redirect('About/index',302);
		return $this->fetch("Login/index");
	}
}